import { http } from "@/utils/http";

// 获取发票列表返回类型
export type InvoiceResult = {
  success: boolean;
  data: {
    total: number;
    page: number;
    page_size: number;
    list: {
      id: number;
      exhibitor_id: number;
      bill_type: string;
      bill_project: string;
      amount: string;
      bill_info: string;
      tax_number: string;
      reg_addres: string;
      reg_phone: string;
      bank: string;
      mail_address: string;
      status: number;
    }[];
  };
};

// 申请发票类型
export type ApplyInvoiceType = {
  id: number;
  exhibitor_id: number;
  bill_type: string;
  bill_project: string;
  amount: string;
  bill_info: string;
  tax_number: string;
  reg_addres: string;
  reg_phone: string;
  bank: string;
  mail_address: string;
  status?: number;
};

// 发票详情返回类型
export type InvoiceDetail = {
  code: number;
  msg: string;
  time: number;
  data: {
    id: number;
    exhibitor_id: number;
    bill_type: string;
    bill_project: string;
    amount: string;
    bill_info: string;
    tax_number: string;
    reg_addres: string;
    reg_phone: string;
    bank: string;
    mail_address: string;
    status: number;
  };
};

// 申请发票返回类型
export type ApplyInvoiceResult = {
  code: number;
  msg: string;
  time: number | string;
};

// 获取发票列表
export const getInvoiceList = (exhibitor_id?: number, page = 1, limit = 5) => {
  return http.request<InvoiceResult>("get", `/api/bill/list`, {
    params: { exhibitor_id, page, limit }
  });
};

// 申请发票
export const applyInvoice = (data: ApplyInvoiceType) => {
  return http.request<ApplyInvoiceResult>("post", "/api/bill/apply", { data });
};

// 获取发票详情
export const getInvoiceDetail = (id: number, exhibitor_id?: number) => {
  return http.request<InvoiceDetail>(
    "get",
    `/api/bill/detail?id=${id}&exhibitor_id=${exhibitor_id}`
  );
};

// 修改发票
export const updateInvoice = (data: ApplyInvoiceType) => {
  return http.request<ApplyInvoiceResult>("post", "/api/bill/update", { data });
};

// 提交审核
export const submitInvoice = (id: number, exhibitor_id: number, status = 0) => {
  return http.request("post", "/api/bill/changeStatus", {
    data: {
      id,
      exhibitor_id,
      status
    }
  });
};
